﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text;

namespace PeisongWeb.admin
{
    public partial class recipeList : adminPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                if (hasPermission("BE", 1))
                {
                    sourceBind();
                    drpBind();
                    rptBind();
                }
                else
                {
                    Library.Script.ClientMsgUrl("没有权限！", "index.aspx");
                    return;
                }
            }
        }
        private void sourceBind()
        {
            DataTable dt=logic.sysCode.recipeFrom();
            ddLSource.DataSource = dt;
            ddLSource.DataBind();
            ddLSource.Items.Insert(0, new ListItem("--请选择--", ""));
        }
        private void drpBind()
        {
            drp_parentType.DataSource = logic.recipeCategory.select("treelevel=0", "rcid", 1000, 1).Tables[1];
            drp_parentType.DataBind();
            drp_parentType.Items.Insert(0, new ListItem("--请选择--", ""));
        }
        void rptBind()
        {
            StringBuilder where = new StringBuilder();
            where.Append(" 1=1");
            if (!String.IsNullOrEmpty(ddLSource.SelectedValue))
                where.AppendFormat(" and source='{0}'",ddLSource.SelectedValue);
            if (drp_parentType.SelectedValue.Trim() != "")
                where.AppendFormat(" and rcid = {0}", Convert.ToInt32(drp_parentType.SelectedValue));
            if (txt_categoryName.Text.Trim() != "")
                where.AppendFormat(" and name like '%{0}%'", txt_categoryName.Text.Trim());

            DataSet ds = logic.recipe.select(where.ToString(), "recipeId", AspNetPager1.PageSize, AspNetPager1.CurrentPageIndex);
            AspNetPager1.RecordCount = Convert.ToInt32(ds.Tables[0].Rows[0][0]);
            rpt_list.DataSource = ds.Tables[1];
            rpt_list.DataBind();
        }
        protected void rpt_list_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "Del")
            {
                int recipeId = Convert.ToInt32(e.CommandArgument);
                logic.recipe.delete(recipeId);
                rptBind();
                Library.Script.ClientMsg("删除成功!");
            }
        }
        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            rptBind();
        }
        protected void lbtn_Search_Click(object sender, EventArgs e)
        {
            rptBind();
        }
    }
}
